package com.example.amusic.screen

import android.app.Activity
import android.os.Build
import android.view.WindowInsetsController
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext

@Composable
fun PlayPageScreen() {
    setPageBar()
    Box(modifier = Modifier.fillMaxSize()) {
        Text(text = "---------状态栏---------")
    }

}

@Composable
fun setPageBar() {
    val localContext = LocalContext.current
    val window = (localContext as Activity).window
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        val inssetsController = window.insetsController
        SideEffect {
            window.statusBarColor = Color.Green.toArgb()
            inssetsController?.setSystemBarsAppearance(
                0,
                WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS
            )
        }
        DisposableEffect(localContext) {
            onDispose {
                window.statusBarColor = Color.Transparent.toArgb()
                inssetsController?.setSystemBarsAppearance(
                    WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
                    WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS,
                )
            }
        }
    }
}